package com.stock.stockana.ui.adapter;

import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.CardView;
import android.support.v7.widget.LinearLayoutCompat;
import android.support.v7.widget.RecyclerView;
import android.text.Html;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.android.volley.toolbox.NetworkImageView;
import com.stock.publiclib.utils.StringUtil;
import com.stock.stockana.R;
import com.stock.stockana.StockCenter;
import com.stock.stockana.beans.News;
import com.stock.stockana.beans.StockInfoBean;
import com.stock.stockana.requests.GetStockNews;
import com.stock.stockana.requests.SetNotifiPrice;
import com.stock.stockana.ui.activities.StockDetailActivity;
import com.stock.stockana.ui.fragments.StockNewsWvFragment;

import java.lang.ref.WeakReference;
import java.text.DateFormat;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.List;
import java.util.Locale;

/**
 * Created by ljgsonx on 2016/1/30.
 */
public class StockDetailAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    RelativeLayout rootView;
    TextView stPriceTv;
    TextView stTrendTv;
    ImageView buyMinusIcon;
    EditText buyNotifiEt;
    ImageView buyAddIcon;
    ImageView saleMinusIcon;
    EditText saleNotifiEt;
    ImageView saleAddIcon;
    ImageView buySwitchIv;
    ImageView saleSwitchIv;
    Button sureSettingBtn;
    Button minKBtn;
    Button dayKBtn;
    Button weakKBtn;
    Button monthKBtn;
    ViewPager kMapViewPager;

    RelativeLayout mNewsPosRL;
    RelativeLayout mNewsNeuRL;
    RelativeLayout mNewsNegRL;
    TextView mNewsPosNumsTv;
    TextView mNewsNeuNumsTv;
    TextView mNewsNegNumsTv;
    ViewPager mNewsVp;
    static LinearLayout[] newsContentLLs = new LinearLayout[3];

    float settedBuyNotifi;
    float settedSaleNotifi;

    int lastBuyState = -1;
    int lastSaleState = -1;

    public Context mContext;
    public LayoutInflater mLayoutInflater;

    private final static int NOTIFI_BUY_ADD = 0;
    private final static int NOTIFI_BUY_MINUS = 1;
    private final static int NOTIFI_SALE_ADD = 2;
    private final static int NOTIFI_SALE_MINUS = 3;

    private StockDetailHandler mStockDetailHander = new StockDetailHandler(this);
    private NotifiThread nt = null;
    private StockInfoBean mStock;
    private List<View> mKMapViews;

    private List<News> mNewsList;

    static class StockDetailHandler extends Handler {

        WeakReference<StockDetailAdapter> weakReference;

        public StockDetailHandler(StockDetailAdapter activity) {
            weakReference = new WeakReference<>(activity);
        }

        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            StockDetailAdapter stockDetailAdapter = weakReference.get();
            if (null != stockDetailAdapter) {
                EditText buyNotifiEt, saleNotifiEt;
                String currentBuy, currentSale;
                buyNotifiEt = stockDetailAdapter.getBuyNotifiEt();
                saleNotifiEt = stockDetailAdapter.getSaleNotifiEt();
                currentBuy = buyNotifiEt.getText().toString();
                currentSale = saleNotifiEt.getText().toString();
                DecimalFormat df = new DecimalFormat("0.000");
                switch (msg.what) {
                    case NOTIFI_BUY_ADD:
                        buyNotifiEt.setText(df.format(Float.parseFloat(currentBuy) + 1));
                        break;
                    case NOTIFI_BUY_MINUS:
                        buyNotifiEt.setText(df.format(Float.parseFloat(currentBuy) - 1));
                        break;
                    case NOTIFI_SALE_ADD:
                        saleNotifiEt.setText(df.format(Float.parseFloat(currentSale) + 1));
                        break;
                    case NOTIFI_SALE_MINUS:
                        saleNotifiEt.setText(df.format(Float.parseFloat(currentSale) - 1));
                        break;
                    default:
                        break;
                }
            }
        }
    }

    class NotifiThread extends Thread {

        private boolean beStart = true;

        private int notifiType;

        public NotifiThread(int notifiType) {
            this.notifiType = notifiType;
        }

        @Override
        public void run() {
            while (beStart) {
                Message msg = new Message();
                msg.what = notifiType;
                mStockDetailHander.sendMessage(msg);
                try {
                    Thread.sleep(100);
                } catch (Exception e) {
                }
            }
        }
    }

    private View.OnTouchListener mOnTouchListener = new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            int notifiType = 0;
            if (v.getId() == buyAddIcon.getId()) {
                notifiType = NOTIFI_BUY_ADD;
            } else if (v.getId() == buyMinusIcon.getId()) {
                notifiType = NOTIFI_BUY_MINUS;
            } else if (v.getId() == saleAddIcon.getId()) {
                notifiType = NOTIFI_SALE_ADD;
            } else {
                notifiType = NOTIFI_SALE_MINUS;
            }
            switch (event.getAction()) {
                case MotionEvent.ACTION_DOWN:
                    nt = new NotifiThread(notifiType);
                    nt.start();
                    break;
                case MotionEvent.ACTION_UP:
                    if (nt != null)
                        nt.beStart = false;
                    break;
                case MotionEvent.ACTION_CANCEL:
                    if (nt != null)
                        nt.beStart = false;
                    break;
                case MotionEvent.ACTION_BUTTON_RELEASE:
                    if (nt != null)
                        nt.beStart = false;
                    break;
                default:
                    break;
            }
            return true;
        }
    };

    private View.OnClickListener kMapBtnClickedListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            switch (v.getId()) {
                case R.id.minKBtn:
                    kMapViewPager.setCurrentItem(0);
                    break;
                case R.id.dayKBtn:
                    kMapViewPager.setCurrentItem(1);
                    break;
                case R.id.weakKBtn:
                    kMapViewPager.setCurrentItem(2);
                    break;
                case R.id.monthKBtn:
                    kMapViewPager.setCurrentItem(3);
                    break;
                default:
                    break;
            }
        }
    };

    private View.OnClickListener mOpenNewsClickedListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            switch (v.getId()) {
                case R.id.newsPosRL:
                    mNewsVp.setCurrentItem(0);
                    break;
                case R.id.newsNeuRL:
                    mNewsVp.setCurrentItem(1);
                    break;
                case R.id.newsNegRL:
                    mNewsVp.setCurrentItem(2);
                    break;
                default:
                    break;
            }
        }
    };

    public void updateStockNewsList() {
        final LayoutInflater layoutInflater = LayoutInflater.from(mContext);
        int posNums = 0;
        int neuNum = 0;
        int negNum = 0;
        for(LinearLayout ll:newsContentLLs){
            ll.removeAllViews();
        }
        for (final News news : GetStockNews.stockNews) {
            CardView cv = (CardView) layoutInflater.inflate(R.layout.stock_info_news_item, null);
            TextView titleTv = (TextView) cv.findViewById(R.id.newsTitle);
            TextView timeTv = (TextView) cv.findViewById(R.id.newsTime);
            TextView contentTv = (TextView) cv.findViewById(R.id.newsContent);
            titleTv.setText(news.getTitle());
            DateFormat df = new SimpleDateFormat("yyyy-MM-dd", Locale.CHINESE);
            if(news.getPubdate() != null)
                timeTv.setText(df.format(news.getPubdate()));
            contentTv.setText(Html.fromHtml(news.getDescription()));
            if ("pos".equals(news.getSentiCate())) {
                newsContentLLs[0].addView(cv);
                posNums++;
            } else if ("n".equals(news.getSentiCate())) {
                newsContentLLs[1].addView(cv);
                neuNum++;
            } else if ("neg".equals(news.getSentiCate())) {
                newsContentLLs[2].addView(cv);
                negNum++;
            }
            cv.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Fragment fg = new StockNewsWvFragment();
                    Bundle bundle = new Bundle();
                    bundle.putString("newsUrl", news.getUrl());
                    fg.setArguments(bundle);
                    FragmentManager fm = ((StockDetailActivity) mContext).getSupportFragmentManager();
                    fm.beginTransaction().setCustomAnimations(R.anim.in_from_right, R.anim.out_from_left,
                                    R.anim.in_from_left, R.anim.out_from_right)
                            .replace(R.id.id_baseFrame, fg).addToBackStack(null).commit();
                }
            });
        }
        CardView cv_nodata;
        if (posNums == 0) {
            cv_nodata = (CardView) layoutInflater.inflate(R.layout.stock_info_news_item_nodata, null);
            newsContentLLs[0].addView(cv_nodata);
        }
        if (neuNum == 0) {
            cv_nodata = (CardView) layoutInflater.inflate(R.layout.stock_info_news_item_nodata, null);
            newsContentLLs[1].addView(cv_nodata);
        }
        if (negNum == 0) {
            cv_nodata = (CardView) layoutInflater.inflate(R.layout.stock_info_news_item_nodata, null);
            newsContentLLs[2].addView(cv_nodata);
        }
        mNewsPosNumsTv.setText(String.valueOf(posNums));
        mNewsNeuNumsTv.setText(String.valueOf(neuNum));
        mNewsNegNumsTv.setText(String.valueOf(negNum));
    }

    public StockDetailAdapter(Context context, StockInfoBean stock) {
        mContext = context;
        mLayoutInflater = LayoutInflater.from(mContext);
        mStock = stock;
        mNewsList = GetStockNews.stockNews;
        GetStockNews getStockNews = GetStockNews.build().setStockNum(mStock.getStNum());
        StockCenter.doReq(getStockNews);
    }

    public EditText getBuyNotifiEt() {
        return buyNotifiEt;
    }

    public EditText getSaleNotifiEt() {
        return saleNotifiEt;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        rootView = (RelativeLayout) mLayoutInflater.inflate(R.layout.stock_info, parent, false);
        initView(rootView);
        configView();
        return new StockDetailHolder(rootView);
    }

    private void initView(View view) {
        stPriceTv = (TextView) view.findViewById(R.id.stPriceTv);
        stTrendTv = (TextView) view.findViewById(R.id.stTrendTv);
        buyMinusIcon = (ImageView) view.findViewById(R.id.buyMinusIcon);
        buyNotifiEt = (EditText) view.findViewById(R.id.buyNotifiEt);
        buyAddIcon = (ImageView) view.findViewById(R.id.buyAddIcon);
        saleMinusIcon = (ImageView) view.findViewById(R.id.saleMinusIcon);
        saleNotifiEt = (EditText) view.findViewById(R.id.saleNotifiEt);
        saleAddIcon = (ImageView) view.findViewById(R.id.saleAddIcon);
        buySwitchIv = (ImageView) view.findViewById(R.id.buySwitchIv);
        saleSwitchIv = (ImageView) view.findViewById(R.id.saleSwitchIv);
        sureSettingBtn = (Button) view.findViewById(R.id.sureSettingBtn);
        minKBtn = (Button) view.findViewById(R.id.minKBtn);
        dayKBtn = (Button) view.findViewById(R.id.dayKBtn);
        weakKBtn = (Button) view.findViewById(R.id.weakKBtn);
        monthKBtn = (Button) view.findViewById(R.id.monthKBtn);
        kMapViewPager = (ViewPager) view.findViewById(R.id.kMapViewPager);

        mNewsPosRL = (RelativeLayout) view.findViewById(R.id.newsPosRL);
        mNewsNeuRL = (RelativeLayout) view.findViewById(R.id.newsNeuRL);
        mNewsNegRL = (RelativeLayout) view.findViewById(R.id.newsNegRL);
        mNewsPosNumsTv = (TextView) view.findViewById(R.id.newsPosNumsTv);
        mNewsNeuNumsTv = (TextView) view.findViewById(R.id.newsNeuNumsTv);
        mNewsNegNumsTv = (TextView) view.findViewById(R.id.newsNegNumsTv);
        mNewsVp = (ViewPager) view.findViewById(R.id.stockNewsVp);
    }

    private void configView() {
        configStockInfoView();
        configKMapViewPager();
        configNewsViewPager();
    }

    private void configStockInfoView() {
        DecimalFormat df1 = new DecimalFormat("0.000");
        stPriceTv.setText(df1.format(mStock.getStPrice()));
        DecimalFormat df2 = new DecimalFormat("0.00");
        String pecentTrend = df2.format(mStock.getStTrend() * 100);
        if (mStock.getStTrend() < 0) {
            stTrendTv.setText(pecentTrend + "%");
            stTrendTv.setTextColor(mContext.getResources().getColor(R.color.c_stock_green));
            stPriceTv.setTextColor(mContext.getResources().getColor(R.color.c_stock_green));
        } else {
            stTrendTv.setText("+" + pecentTrend + "%");
            stTrendTv.setTextColor(mContext.getResources().getColor(R.color.c_stock_red));
            stPriceTv.setTextColor(mContext.getResources().getColor(R.color.c_stock_red));
        }
        boolean hasSetNotifi = false;
        if (mStock.getDowntriggerprice() == 0) {
            buyNotifiEt.setText(df1.format(mStock.getStPrice()));
        } else {
            buyNotifiEt.setText(df1.format(mStock.getDowntriggerprice()));
            hasSetNotifi = true;
        }
        if (mStock.getUptriggerprice() == 0) {
            saleNotifiEt.setText(df1.format(mStock.getStPrice()));
        } else {
            saleNotifiEt.setText(df1.format(mStock.getUptriggerprice()));
            hasSetNotifi = true;
        }
        buyMinusIcon.setOnTouchListener(mOnTouchListener);
        buyAddIcon.setOnTouchListener(mOnTouchListener);
        saleAddIcon.setOnTouchListener(mOnTouchListener);
        saleMinusIcon.setOnTouchListener(mOnTouchListener);
        String remindStatus = mStock.getRemindStatus();
        if(!StringUtil.isBlank(remindStatus) && remindStatus.length() == 2){
            char buyStatus = remindStatus.charAt(0);
            char saleStatus = remindStatus.charAt(1);
            if(buyStatus == '0'){
                lastBuyState = 0;
                buySwitchIv.setSelected(false);
            }else{
                lastBuyState = 1;
                buySwitchIv.setSelected(true);
            }
            if(saleStatus == '0'){
                lastSaleState = 0;
                saleSwitchIv.setSelected(false);
            }else{
                lastSaleState = 1;
                saleSwitchIv.setSelected(true);
            }
        }
        buySwitchIv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (buySwitchIv.isSelected()) {
                    buySwitchIv.setSelected(false);
                } else {
                    buySwitchIv.setSelected(true);
                }
            }
        });
        saleSwitchIv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (saleSwitchIv.isSelected()) {
                    saleSwitchIv.setSelected(false);
                } else {
                    saleSwitchIv.setSelected(true);
                }
            }
        });

        if ((mStock.getNote() == StockInfoBean.STATUS_ADDED) && hasSetNotifi) {
            sureSettingBtn.setText("重新设置");
        } else if (mStock.getNote() == StockInfoBean.STATUS_NOTADDED) {
            disableSureSettingBtn();
        }
        sureSettingBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                SetNotifiPrice setNotifiPrice = SetNotifiPrice.build(mStock.getStNum());
                settedBuyNotifi = Float.parseFloat(buyNotifiEt.getText().toString());
                settedSaleNotifi = Float.parseFloat(saleNotifiEt.getText().toString());
                int buyStatus = buySwitchIv.isSelected()?1:0;
                int saleStatus = saleSwitchIv.isSelected()?1:0;
                setNotifiPrice.setRemindStatus(buyStatus +""+ saleStatus);
                if (lastSaleState == 0 && saleStatus == 0 && lastBuyState == 0 && buyStatus == 0) {
                    Toast.makeText(mContext, "请先开启提醒按钮!", Toast.LENGTH_LONG).show();
                    return;
                }
                boolean notCorrect = false;
                DecimalFormat df1 = new DecimalFormat("0.000");
                float priceNow = Float.valueOf(df1.format(mStock.getStPrice()));
                if(buyStatus == 1){
                    if (settedBuyNotifi >= priceNow || settedBuyNotifi <= 0) {
                        notCorrect = true;
                        Toast.makeText(mContext, "设置的买入价必须小于当前价格", Toast.LENGTH_LONG).show();
                    }else {
                        setNotifiPrice.setDownTrigger(String.valueOf(settedBuyNotifi));
                    }
                }
                if(saleStatus == 1){
                    if (settedSaleNotifi <= priceNow || settedSaleNotifi <= 0) {
                        notCorrect = true;
                        Toast.makeText(mContext, "设置的卖出价必须大于当前价格", Toast.LENGTH_LONG).show();
                    }else {
                        setNotifiPrice.setUpTrigger(String.valueOf(settedSaleNotifi));
                    }
                }
                if (!notCorrect) {
                    StockCenter.doReq(setNotifiPrice);
                }
            }
        });
    }

    private void configKMapViewPager() {
        NetworkImageView[] nivs = new NetworkImageView[4];
        for (int i = 0; i < nivs.length; i++) {
            nivs[i] = new NetworkImageView(mContext);
            nivs[i].setScaleType(ImageView.ScaleType.FIT_CENTER);
            nivs[i].setDefaultImageResId(R.drawable.loading_iamge);
            nivs[i].setErrorImageResId(R.drawable.loading_image_error);
            nivs[i].setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    View view = LayoutInflater.from(mContext).inflate(R.layout.kmap_layout, null);
                    view.setFocusable(true);
                    view.setFocusableInTouchMode(true);
                    final ImageView iv = (ImageView) view.findViewById(R.id.kMapIv);
                    iv.setImageDrawable(((NetworkImageView) v).getDrawable());
                    final PopupWindow popupWindow = new PopupWindow(view, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT, true);
                    popupWindow.setTouchable(true);
                    popupWindow.setFocusable(true);
                    popupWindow.setAnimationStyle(R.style.PopupAnimation);
                    popupWindow.showAtLocation(rootView, Gravity.CENTER, 0, 0);
                    view.setOnKeyListener(new View.OnKeyListener() {
                        @Override
                        public boolean onKey(View v, int keyCode, KeyEvent event) {
                            if (keyCode == KeyEvent.KEYCODE_BACK) {
                                popupWindow.dismiss();
                                return true;
                            }
                            return false;
                        }
                    });
                }
            });
        }
        nivs[0].setImageUrl(mStock.getMinK(), StockCenter.getImageLoader());
        nivs[1].setImageUrl(mStock.getDayK(), StockCenter.getImageLoader());
        nivs[2].setImageUrl(mStock.getWeeK(), StockCenter.getImageLoader());
        nivs[3].setImageUrl(mStock.getMonK(), StockCenter.getImageLoader());
        kMapViewPager.setAdapter(new SimpleViewPagerAdapter(nivs));
        kMapViewPager.setCurrentItem(0);
        kMapViewPager.setOnPageChangeListener(new KMapViewChangedListener());
        minKBtn.setSelected(true);
        minKBtn.setOnClickListener(kMapBtnClickedListener);
        dayKBtn.setOnClickListener(kMapBtnClickedListener);
        weakKBtn.setOnClickListener(kMapBtnClickedListener);
        monthKBtn.setOnClickListener(kMapBtnClickedListener);
    }

    private void configNewsViewPager() {
        for (int i = 0; i < newsContentLLs.length; i++) {
            newsContentLLs[i] = new LinearLayout(mContext);
            newsContentLLs[i].setOrientation(LinearLayout.VERTICAL);
            newsContentLLs[i].setLayoutParams(new LinearLayoutCompat.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                    ViewGroup.LayoutParams.WRAP_CONTENT));
        }
        mNewsVp.setAdapter(new SimpleViewPagerAdapter(newsContentLLs));
        mNewsVp.setCurrentItem(0);
        mNewsVp.setOnPageChangeListener(new NewsViewChangedListener());
        mNewsPosRL.setSelected(true);
        mNewsPosRL.setOnClickListener(mOpenNewsClickedListener);
        mNewsNeuRL.setOnClickListener(mOpenNewsClickedListener);
        mNewsNegRL.setOnClickListener(mOpenNewsClickedListener);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {

    }

    public void disableSureSettingBtn() {
        sureSettingBtn.setBackgroundResource(R.drawable.greywhite_btn_bg_pressed);
        sureSettingBtn.setEnabled(false);
        sureSettingBtn.setText("请先添加为自选股");
    }

    public void enableSureSettingBtn() {
        sureSettingBtn.setBackgroundResource(R.drawable.greywhite_btn_bg);
        sureSettingBtn.setEnabled(true);
        sureSettingBtn.setText("开 启 叫 醒");
    }

    public void setSureSettingBtnText(String text) {
        sureSettingBtn.setText(text);
    }

    public void updateStockPrice() {
        mStock.setDowntriggerprice(settedBuyNotifi);
        mStock.setUptriggerprice(settedSaleNotifi);
    }

    @Override
    public int getItemCount() {
        return 1;
    }

    class StockDetailHolder extends RecyclerView.ViewHolder {

        public StockDetailHolder(View itemView) {
            super(itemView);
        }
    }

    class SimpleViewPagerAdapter extends PagerAdapter {
        private View[] mListViews;

        public SimpleViewPagerAdapter(View[] mListViews) {
            this.mListViews = mListViews;
        }

        @Override
        public void destroyItem(ViewGroup container, int position, Object object) {
            container.removeView(mListViews[position]);
        }

        @Override
        public Object instantiateItem(ViewGroup container, int position) {
            container.addView(mListViews[position], 0);
            return mListViews[position];
        }

        @Override
        public int getCount() {
            return mListViews.length;
        }

        @Override
        public boolean isViewFromObject(View arg0, Object arg1) {
            return arg0 == arg1;
        }
    }

    class KMapViewChangedListener implements ViewPager.OnPageChangeListener {

        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
        }

        @Override
        public void onPageSelected(int position) {
            switch (position) {
                case 0:
                    minKBtn.setSelected(true);
                    dayKBtn.setSelected(false);
                    weakKBtn.setSelected(false);
                    monthKBtn.setSelected(false);
                    break;
                case 1:
                    minKBtn.setSelected(false);
                    dayKBtn.setSelected(true);
                    weakKBtn.setSelected(false);
                    monthKBtn.setSelected(false);
                    break;
                case 2:
                    minKBtn.setSelected(false);
                    dayKBtn.setSelected(false);
                    weakKBtn.setSelected(true);
                    monthKBtn.setSelected(false);
                    break;
                case 3:
                    minKBtn.setSelected(false);
                    dayKBtn.setSelected(false);
                    weakKBtn.setSelected(false);
                    monthKBtn.setSelected(true);
                    break;
                default:
                    break;
            }
        }

        @Override
        public void onPageScrollStateChanged(int state) {
        }
    }

    class NewsViewChangedListener implements ViewPager.OnPageChangeListener {

        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
        }

        @Override
        public void onPageSelected(int position) {
            switch (position) {
                case 0:
                    mNewsPosRL.setSelected(true);
                    mNewsNeuRL.setSelected(false);
                    mNewsNegRL.setSelected(false);
                    break;
                case 1:
                    mNewsPosRL.setSelected(false);
                    mNewsNeuRL.setSelected(true);
                    mNewsNegRL.setSelected(false);
                    break;
                case 2:
                    mNewsPosRL.setSelected(false);
                    mNewsNeuRL.setSelected(false);
                    mNewsNegRL.setSelected(true);
                    break;
                default:
                    break;
            }
        }

        @Override
        public void onPageScrollStateChanged(int state) {
        }
    }
}
